<template>
  <ele-page>
    <!-- 搜索表单 -->
    <!-- <search @search="reload" :where="defaultWhere" /> -->
    <ele-card :body-style="{ paddingTop: '8px' }">
      <!-- 表格 -->
      <ele-pro-table
        ref="tableRef"
        row-key="userId"
        :columns="columns"
        :datasource="datasource"
        :show-overflow-tooltip="true"
        v-model:selections="selections"
        highlight-current-row
        border
        stripe
      >
        <template #buyer="{ row }">
          <span class="pointer blue" @click="showStudentDetail(row.buyer.id)">
            {{ row.buyer }}
          </span>
        </template>
        <template #bouns_user="{ row }">
          <span
            class="pointer blue"
            @click="showStudentDetail(row.bouns_user_id)"
          >
            {{ row.bouns_user }}
          </span>
        </template>
      </ele-pro-table>
    </ele-card>
    <!-- 学生详情 -->
    <detail v-model="showDetail" :student-id="currentId" @done="reload" />
  </ele-page>
</template>

<script setup>
  import { ref } from 'vue';

  import Detail from '@/views/student/components/detail.vue';
  import { pageMallTradeBouns } from '@/api/mall';

  /** 表格实例 */
  const tableRef = ref(null);

  /** 表格列配置 */
  const columns = ref([
    {
      prop: 'goods_title',
      label: '商品',
      miniWidth: 250
    },
    {
      slot: 'buyer',
      label: '购买人',
      width: 100
    },
    {
      slot: 'bouns_user',
      label: '推荐人',
      width: 100
    },
    {
      prop: 'amount',
      label: '佣金',
      align: 'center',
      width: 100
    },
    {
      prop: 'create_time',
      label: '发放时间',
      width: 180,
      align: 'center'
    }
  ]);

  /** 表格选中数据 */
  const selections = ref([]);

  /** 当前编辑数据 */
  const current = ref(null);

  /** 当前编辑数据 */
  const currentId = ref(null);

  /** 是否显示编辑弹窗 */
  const showJudge = ref(false);

  /** 是否显示编辑弹窗 */
  const showDetail = ref(false);

  /** 表格数据源 */
  const datasource = ({ page, limit, where, orders }) => {
    return pageMallTradeBouns({
      ...where,
      ...orders,
      page,
      limit,
      wating_pay: 1
    });
  };

  /** 搜索 */
  const reload = (where) => {
    selections.value = [];
    tableRef.value?.reload?.({ page: 1, where });
  };

  /** 打开编辑弹窗 */
  const showStudentDetail = (row) => {
    currentId.value = row.id ?? 0;
    showDetail.value = true;
  };
</script>

<script>
  export default {
    name: 'SystemUser'
  };
</script>
